package
{
	import fl.controls.Label;
	
	import flare.display.TextSprite;
	
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	
	public class DoubleInputText extends Sprite
	{
		private var fieldName:String;
		
		private var inputTextL:TextField;
		private var inputTextR:TextField;
		
		private var button:Sprite;
		
		public function DoubleInputText(fieldName:String)
		{
			this.fieldName = fieldName;
			
			// add octagon icon
			var octL:Octagon = new Octagon("A", 10);
			octL.x = 0;
			octL.y = 13;
			this.addChild(octL);
			
			// add label
			var labelL:TextSprite = new TextSprite("Starting Point");
			labelL.color = 0x000000;
			labelL.x = 55;
			labelL.y = 17;
			labelL.size = 20;
			this.addChild(labelL);
			
			// add input text field
			inputTextL = new TextField();
			inputTextL.type = TextFieldType.INPUT;
			inputTextL.x = 55;
			inputTextL.y = 40;
			inputTextL.width = 220;
			inputTextL.height = 20;
			inputTextL.border = true;
			this.addChild(inputTextL);
			
			// add octagon icon
			var octR:Octagon = new Octagon("B", 10);
			octR.x = 320;
			octR.y = 13;
			this.addChild(octR);
			
			// add label
			var labelR:TextSprite = new TextSprite("Ending Point");
			labelR.color = 0x000000;
			labelR.x = 375;
			labelR.y = 17;
			labelR.size = 20;
			this.addChild(labelR);
			
			// add input text field
			inputTextR = new TextField();
			inputTextR.type = TextFieldType.INPUT;
			inputTextR.x = 375;
			inputTextR.y = 40;
			inputTextR.width = 220;
			inputTextR.height = 20;
			inputTextR.border = true;
			this.addChild(inputTextR);
			
			// add button
			button = new Sprite();
			button.x = 660;
			button.y = 20;
			button.graphics.lineStyle(2, 0x009999);
			button.graphics.beginFill(0x33cccc);
			button.graphics.drawRoundRect(0, 0, 140, 40, 10, 10);
			button.graphics.endFill();
			button.visible = true;
			this.addChild(button);
			button.addEventListener(MouseEvent.CLICK, onClick);
			
			// add button text on top of button
			var buttonText:TextSprite = new TextSprite(fieldName);
			buttonText.x = 8;
			buttonText.y = 7;
			buttonText.color = 0xFFFFFF;
			buttonText.size = 20;
			buttonText.font = "Arial";
			button.addChild(buttonText);
		}
		
		private function onClick(e:Event):void {
			this.dispatchEvent(new Event(this.fieldName, true));
		}
		
		public function getTextContent():Array {
			var result:Array = new Array();
			result.push(inputTextL.text);
			result.push(inputTextR.text);
			
			return result;
		}
	}
}